package com.zjkj.mp.dao.message.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zjkj.mp.dao.DaoBase;
import com.zjkj.mp.dao.message.MessageDao;
import com.zjkj.mp.utils.PaginatedResult;
import com.zjkj.mp.vo.Logger;
import com.zjkj.mp.vo.message.Message;
import com.zjkj.mp.vo.message.MessageMx;

@Repository
public class MessageDaoImpl extends DaoBase implements MessageDao {

	public void insertLogger(Logger logger) {
		getSqlMapClient().insert("ins.insertLogger", logger);
	}

	@Override
	public void insertMessageMx(MessageMx mx) {
		getSqlMapClient().insert("ins.insertMessageMx", mx);
	}

	@Override
	public void insertMessage(Message msg) {
		getSqlMapClient().insert("ins.insertMessage", msg);
	}

	@Override
	public int searchMessageCount(String fsId) {
		int count = (Integer)getSqlMapClient().queryForObject("get.searchMessageCount", fsId);
		return count;
	}

	@Override
	public PaginatedResult getList(int pageNo, int pageSize,	Map<String, Object> params) {
		PaginatedResult result = new PaginatedResult(pageNo,pageSize);
		List list = getSqlMapClient().queryForList("get.shMessageList",params,(pageNo-1)*pageSize , pageSize);
		Object count = getSqlMapClient().queryForObject("get.shMessageListCount",params);
		
		result.setResult(list);
		result.setTotalSize(count == null? 0:(Integer)count);
		
		return result;
	}

	@Override
	public void updateMessageState(String  fsId, String newState) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("fsId", fsId);
		params.put("newState",newState);
		
		getSqlMapClient().update("update.messageState",params);
	}

	@Override
	public void updateMessage(Message msg) {
		getSqlMapClient().update("update.updateMessage", msg);
	}

	@Override
	public void updateMessageCount(long balance, int UserId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("balance", balance);
		params.put("UserId",UserId);
		getSqlMapClient().update("update.updateMessageCount", params);
	}
}
